package com.jy.adscm.operation.hscrb.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.operation.hscrb.bean.MjglMoulddetail;
import com.jy.adscm.operation.hscrb.mapper.mysql.MjglMoulddetailMapper;
import com.jy.adscm.operation.hscrb.service.MjglMoulddetailService;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2018-12-18
 */
@Service
public class MjglMoulddetailServiceImpl extends ServiceImpl<MjglMoulddetailMapper, MjglMoulddetail> implements MjglMoulddetailService {
  @Autowired
    JyUserMapper jyUserMapper;
    @Override
    public Boolean updateMjglMoulddetail(MjglMoulddetail mjglMoulddetail) {
        boolean result = super.updateById(mjglMoulddetail);
        return result;
    }

    @Override
    public List<MjglMoulddetail> selectByTid(String tid) {
        Wrapper<MjglMoulddetail> wrapper =new EntityWrapper<>();
        wrapper.eq("TID",tid);
        List<MjglMoulddetail> mjglMoulddetails = super.selectList(wrapper);
        for (MjglMoulddetail mjglMoulddetail : mjglMoulddetails) {
             if (AdscmBaseUtils.getInstance().isNotEmpty(mjglMoulddetail.getCustomer(),null)){
                 JyUser jyUser = jyUserMapper.selectById(mjglMoulddetail.getCustomer());
                 mjglMoulddetail.setCustomerName(jyUser.getName());
             }
        }
        return mjglMoulddetails;
    }

    @Override
    public List<JyUser> selectUser() {
        Wrapper<JyUser> wrapper=new EntityWrapper<>();
        wrapper.setSqlSelect("id","name");
        List<JyUser> jyUsers = jyUserMapper.selectList(wrapper);
        return jyUsers;

    }
}
